<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Server\WheatPriceServer;
use App\Services\JsonResponseService;
use Illuminate\Http\Request;

class WheatPriceController extends Controller
{
    //小麦价格管理
    public function __construct() {
        $this->server = new WheatPriceServer();
    }

    /**
     * 添加小麦价格
     * @param Request $request
     */
    public function addWheatPrice(Request $request){
        $id = $request->input('id');
        $now_date = $request->input('now_date');
        $cost_price = $request->input('cost_price');
        $sales_price = $request->input('sales_price');
        $res = $this->server->addWheatPriceServer($id,$now_date,$cost_price,$sales_price);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }

    /**
     * 获取产品列表
     */
    public function getWheatPriceList(Request $request){
        // 获取查询条件
        $params = $request->only(['now_date']);
        $per_page = $request->input('per_page');
        $res = $this->server->getWheatPriceListServer($params,$per_page);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }

    /**
     * 获取最新的小麦价格
     * @param Request $request
     * @return void
     */
    public function getWheatPriceNew(Request $request)
    {
        $res = $this->server->getWheatPriceNewServer();
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }
}
